{extend name="common/adminBase" /}
{block name="body"}
<style>
  .layui-input-inline{
    width: 700px !important;
  }
  .layui-form-label{
    width:150px;
  }
  .date{
    width:260px; display: inline-block;
  }
  #uploadimg{
    position: absolute;
    top:155px;left:1060px;
  }
  .layui-upload-img {
    width: 92px;
    height: 92px;
  }
</style>
<body>
<div class="layui-fluid">
  <div class="layui-row">
    <form class="layui-form">
      <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>学校信息</legend>
      </fieldset>
      <input type="hidden" name="id" value="{$info.id}" />
      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>学校名称
        </label>
        <div class="layui-input-inline">
          <input type="text"  name="name" placeholder="请输入姓名" value="{$info.name}" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
        </div>
      </div>

      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>学校地址
        </label>
        <div class="layui-input-inline">
          <input type="text"  name="address" placeholder="请输入学校地址" value="{$info.address}" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
        </div>
      </div>

      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>学校邮箱
        </label>
        <div class="layui-input-inline">
          <input type="text"  name="email" placeholder="请输入邮箱" value="{$info.email}" id="mail" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
        </div>
      </div>

      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>学校教师人数
        </label>
        <div class="layui-input-inline">
          <input type="number"  name="teacher_num" value="{$info.teacher_num}" placeholder="请输入学校教师人数" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="username" class="layui-form-label">
          <span class="x-red">*</span>专职教师人数
        </label>
        <div class="layui-input-inline">
          <input type="number"  name="zhuan_num" value="{$info.zhuan_num}" placeholder="请输入专职教师人数" required="" lay-verify="required"
                 autocomplete="off" class="layui-input">
        </div>
      </div>
      <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>功能教室 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</legend>
      </fieldset>
      {volist name="gongneng" id="vo"}
      <div id="gongneng_1000{$key}">
        <div class="layui-form-item">
          <label for="username" class="layui-form-label">
            <span class="x-red">*</span>{$vo.name}
            <input type="hidden" name="gongnengname[]" value="{$vo.name}" />
          </label>
          <div class="layui-input-inline">
            <input type="number" style="width:380px;" name="gongneng[]" value="{$vo.mianji}" placeholder="请输入个体辅导室平米数" required="" lay-verify="required"
                   autocomplete="off" class="layui-input">

          </div>
        </div>
      </div>
      {/volist}

      <div id="add_html"></div>

      <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>开设心理课程信息 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</legend>
      </fieldset>
      {volist name="class" id="vo"}
      <div id="classinfo_1000{$key}">
        <div class="layui-form-item">
          <label for="username" class="layui-form-label">
            <span class="x-red">*</span>心理课程名称
          </label>
          <div class="layui-input-inline">
            <input type="text"  name="class_name[]" value="{$vo.name}" placeholder="请输入心理课程名称" required="" lay-verify="required"
                   autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label for="username" class="layui-form-label">
            <span class="x-red">*</span>课时
          </label>
          <div class="layui-input-inline">
            <input type="text"  name="class_time[]" value="{$vo.times}" placeholder="请输课时" required="" lay-verify="required"
                   autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label for="username" class="layui-form-label">
            <span class="x-red">*</span>授课方式
          </label>
          <div class="layui-input-inline">
            <input type="text"  name="class_type[]" value="{$vo.type}" placeholder="请输入授课方式" required="" lay-verify="required"
                   autocomplete="off" class="layui-input">
          </div>
        </div>

        <div class="layui-form-item">
          <label for="username" class="layui-form-label">
            <span class="x-red">*</span>主讲教师
          </label>
          <div class="layui-input-inline">
            <input type="text"  name="class_teacher[]" value="{$vo.teacher}" placeholder="请输入主讲教师" required="" lay-verify="required"
                   autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label for="username" class="layui-form-label">
            <span class="x-red">*</span>课程介绍
          </label>
          <div class="layui-input-inline">
            <textarea name="class_info[]" class="layui-textarea">{$vo.info}</textarea>

          </div>
        </div>
      </div>
      {/volist}
      <div id="add_html2"></div>
      <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>专职老师信息 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
      </fieldset>
      {volist name="teacher" id="vo"}
      <div id ="teacher_1000{$key}">
        <div class="layui-form-item">
          <label for="username" class="layui-form-label">
            <span class="x-red">*</span>姓名
          </label>
          <div class="layui-input-inline">
            <input type="text"  name="teacher_name[]" value="{$vo.name}" placeholder="请输入姓名" required="" lay-verify="required"
                   autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label for="username" class="layui-form-label">
            <span class="x-red">*</span>性别
          </label>
          <div class="layui-input-inline">
            <select name="teacher_sex[]">
              <option value="">选择性别</option>
              <option value="男" {if $vo.sex=="男"}selected{/if}>男</option>
              <option value="女" {if $vo.sex=="女"}selected{/if}>女</option>
            </select>
          </div>
        </div>
        <div class="layui-form-item">
          <label for="username" class="layui-form-label">
            <span class="x-red">*</span>年龄
          </label>
          <div class="layui-input-inline">
            <input type="num"  name="teacher_year[]" value="{$vo.year}" placeholder="请输入年龄" required="" lay-verify="required"
                   autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label for="username" class="layui-form-label">
            <span class="x-red">*</span>工作年限
          </label>
          <div class="layui-input-inline">
            <input name="work_stime[]" placeholder="开始时间" autocomplete="off"  class="layui-input date"/> 至 <input name="work_etime[]" placeholder="截止时间" autocomplete="off"  class="layui-input date"/> {$vo.work}
          </div>
        </div>
        <div class="layui-form-item">
          <label for="username" class="layui-form-label">
            <span class="x-red">*</span>证书登记
          </label>
          <div class="layui-input-inline">
            <select name="teacher_zhizheng[]">
              <option value="">请选择</option>
              <option value="A1证" {if $vo.zhizheng=="A1证"}selected{/if}>A1证</option>
              <option value="A2证" {if $vo.zhizheng=="A2证"}selected{/if}>A2证</option>
              <option value="B1证" {if $vo.zhizheng=="B1证"}selected{/if}>B1证</option>
              <option value="B2证" {if $vo.zhizheng=="B2证"}selected{/if}>B2证</option>
              <option value="C证" {if $vo.zhizheng=="C证"}selected{/if}>C证</option>
            </select>
          </div>
        </div>
        {if $vo.field!=''}
        <div class="layui-form-item">
          <label for="username" class="layui-form-label">
            <span class="x-red">*</span>资料下载
          </label>
          <div class="layui-input-inline">
            <a type="button" class="layui-btn upload" id="1" href="{$vo.field}"><i class="layui-icon"></i>下载文件</a>
            <input type="hidden" name="teach_field[]" id="field_1" />
          </div>

        </div>
        {/if}
      </div>
      {/volist}
      <div id="teacher"></div>

    </form>
  </div>
</div>
<script>layui.use(['form', 'layer','laydate','upload'],
        function() {
          $ = layui.jquery;
          var form = layui.form, layer = layui.layer;
          var laydate = layui.laydate;
          var upload = layui.upload;


          lay('.date').each(function () {
            laydate.render({
              elem: this, //元素
            });
          });
          lay('.upload').each(function () {
            upload.render({
              elem: this
              , url: '/index/index/uploadfield' //改成您自己的上传接口
              , accept: 'file' //普通文件
              // ,before:function(obj){
              //
              // }
              , done: function (res) {
                // console.log(this.item.attr('id'));
                $("#field_"+this.item.attr('id')).val(res.msg);
                layer.msg("上传成功");
              }
            });
          });
          //监听提交
          form.on('submit(add)', function(data) {

            //验证邮箱
            var myReg=/^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/;
            var myemail = $("#mail").val();
            if(!myReg.test(myemail)){
              layer.msg('邮箱格式不对!');
              return false;
            }
            //发异步，把数据提交给php
            $.ajax({
              url:"/index/school/index",
              data:data.field,
              type:'post',
              dataType:'json',
              success:function (res) {
                if (res.status==1){
                  layer.msg("更新成功",{icon:6,time:1500},function() {
                    window.href = '';
                  });
                }else{
                  layer.alert(res.msg,function (index) {
                    layer.close(index);
                  })
                }
              }
            })

            return false;
          });

        });
var gongneng = 2;
function add(){
  var html ='';
  gongneng+=1;
  html =  '<div id="gongneng_'+gongneng+'">'+
          '<div class="layui-form-item">\n' +
          '        <label for="username" class="layui-form-label">\n' +
          '          <input type="text" style="position: relative;top:-10px;" class="layui-input" name="gongnengname['+gongneng+']" value="" />\n' +
          '        </label>\n' +
          '        <div class="layui-input-inline">\n' +
          '          <input type="number"  name="gongneng['+gongneng+']" placeholder="请输入平米数" required="" lay-verify="required"\n' +
          '                 autocomplete="off" style="width:350px;" class="layui-input"><button type="button" style="position: relative;top:-30px;left:400px;" class="layui-btn layui-btn-danger" onclick="lot('+gongneng+')">删除</button>\n' +
          '        </div>\n' +
          '      </div>'+
          '</div>';
  $("#add_html").append(html);
}
function lot(n){
  $("#gongneng_"+n).remove();
}
var classinfo=0;
function add1(){
  var html ='';
  classinfo+=1;
  html = '<div id="classinfo_'+classinfo+'">'+
          '<div class="layui-form-item">\n' +
          '        <label for="username" class="layui-form-label">\n' +
          '          <span class="x-red">*</span>心理课程名称\n' +
          '        </label>\n' +
          '        <div class="layui-input-inline">\n' +
          '          <input type="text"  name="class_name['+classinfo+']" placeholder="请输入心理课程名称" required="" lay-verify="required"\n' +
          '                 autocomplete="off" class="layui-input">\n' +
          '        </div>\n' +
          '      </div>\n' +
          '      <div class="layui-form-item">\n' +
          '        <label for="username" class="layui-form-label">\n' +
          '          <span class="x-red">*</span>课时\n' +
          '        </label>\n' +
          '        <div class="layui-input-inline">\n' +
          '          <input type="text"  name="class_time['+classinfo+']" placeholder="请输课时" required="" lay-verify="required"\n' +
          '                 autocomplete="off" class="layui-input">\n' +
          '        </div>\n' +
          '      </div>\n' +
          '      <div class="layui-form-item">\n' +
          '        <label for="username" class="layui-form-label">\n' +
          '          <span class="x-red">*</span>授课方式\n' +
          '        </label>\n' +
          '        <div class="layui-input-inline">\n' +
          '          <input type="text"  name="class_type['+classinfo+']" placeholder="请输入授课方式" required="" lay-verify="required"\n' +
          '                 autocomplete="off" class="layui-input">\n' +
          '        </div>\n' +
          '      </div>\n' +
          '\n' +
          '      <div class="layui-form-item">\n' +
          '        <label for="username" class="layui-form-label">\n' +
          '          <span class="x-red">*</span>主讲教师\n' +
          '        </label>\n' +
          '        <div class="layui-input-inline">\n' +
          '          <input type="text"  name="class_teacher['+classinfo+']" placeholder="请输入主讲教师" required="" lay-verify="required"\n' +
          '                 autocomplete="off" class="layui-input">\n' +
          '        </div>\n' +
          '      </div>\n' +
          '      <div class="layui-form-item">\n' +
          '        <label for="username" class="layui-form-label">\n' +
          '          <span class="x-red">*</span>课程介绍\n' +
          '        </label>\n' +
          '        <div class="layui-input-inline">\n' +
          '          <textarea name="class_info['+classinfo+']" class="layui-textarea"></textarea>\n' +
          '        </div>\n<button type="button" style="position: relative;top:-10px;left:100px;" class="layui-btn layui-btn-danger" onclick="lot1('+classinfo+')">删除</button>' +
          '      </div></div>';
  $("#add_html2").append(html);
}
function lot1(n){
  // alert(123);
  $("#classinfo_"+n).remove();
}
var teacher = 1;
function add2(){
  var html = '';
  teacher +=1;
  html =  '<div id="teacher_'+teacher+'">'+
          '<div class="layui-form-item">\n' +
          '        <label for="username" class="layui-form-label">\n' +
          '          <span class="x-red">*</span>姓名\n' +
          '        </label>\n' +
          '        <div class="layui-input-inline">\n' +
          '          <input type="text"  name="teacher_name['+teacher+']" placeholder="请输入姓名" required="" lay-verify="required"\n' +
          '                 autocomplete="off" class="layui-input">\n' +
          '        </div>\n' +
          '      </div>\n' +
          '      <div class="layui-form-item">\n' +
          '        <label for="username" class="layui-form-label">\n' +
          '          <span class="x-red">*</span>性别\n' +
          '        </label>\n' +
          '        <div class="layui-input-inline">\n' +
          '          <select name="teacher_sex['+teacher+']">\n' +
          '            <option value="">选择性别</option>\n' +
          '            <option value="男">男</option>\n' +
          '            <option value="女">女</option>\n' +
          '          </select>\n' +
          '        </div>\n' +
          '      </div>\n' +
          '      <div class="layui-form-item">\n' +
          '        <label for="username" class="layui-form-label">\n' +
          '          <span class="x-red">*</span>年龄\n' +
          '        </label>\n' +
          '        <div class="layui-input-inline">\n' +
          '          <input type="num"  name="teacher_year['+teacher+']" placeholder="请输入年龄" required="" lay-verify="required"\n' +
          '                 autocomplete="off" class="layui-input">\n' +
          '        </div>\n' +
          '      </div>\n' +
          '      <div class="layui-form-item">\n' +
          '        <label for="username" class="layui-form-label">\n' +
          '          <span class="x-red">*</span>工作年限\n' +
          '        </label>\n' +
          '        <div class="layui-input-inline">\n' +
          '          <input name="work_stime['+teacher+']" placeholder="开始时间" autocomplete="off"  class="layui-input date"/> 至 <input name="work_etime['+teacher+']" placeholder="截止时间" autocomplete="off"  class="layui-input date"/>\n' +
          '        </div>\n' +
          '      </div>\n' +
          '      <div class="layui-form-item">\n' +
          '        <label for="username" class="layui-form-label">\n' +
          '          <span class="x-red">*</span>证书登记\n' +
          '        </label>\n' +
          '        <div class="layui-input-inline">\n' +
          '          <select name="teacher_zhizheng['+teacher+']">\n' +
          '            <option value="">请选择</option>\n' +
          '            <option value="A1证">A1证</option>\n' +
          '            <option value="A2证">A2证</option>\n' +
          '            <option value="B1证">B1证</option>\n' +
          '            <option value="B2证">B2证</option>\n' +
          '            <option value="C证">C证</option>\n' +
          '          </select>\n' +
          '        </div>\n' +
          '      </div>\n' +
          '      <div class="layui-form-item">\n' +
          '        <label for="username" class="layui-form-label">\n' +
          '          <span class="x-red">*</span>资料上传\n' +
          '        </label>\n' +
          '        <div class="layui-input-inline">\n' +
          '          <button type="button" class="layui-btn upload" id="'+teacher+'"><i class="layui-icon"></i>上传文件</button>\n' +
          '          <input type="hidden" name="teach_field['+teacher+']" id="field_'+teacher+'" />\n' +
          '        </div>\n<button type="button" style="position: relative;left:50px;" class="layui-btn layui-btn-danger" onclick="lot2('+teacher+')">删除</button>' +
          '      </div></div>';
  $("#teacher").append(html);
  layui.use(['laydate','form','upload'], function(){
    var laydate = layui.laydate;
    var upload = layui.upload;
    var form = layui.form;
    form.render();
    //对每个laydate
    lay('.date').each(function(){
      laydate.render({
        elem: this,
        trigger: 'click'
      });
    });
    lay('.upload').each(function () {
      upload.render({
        elem: this
        , url: '/index/index/uploadfield' //改成您自己的上传接口
        , accept: 'file' //普通文件
        , done: function (res) {
          $("#field_"+this.item.attr('id')).val(res.msg);
          layer.msg("上传成功");
        }
      });
    });
  });
}

function lot2(n){
  $("#teacher_"+n).remove();
}
</script>
</body>

{/block}
